<?php
namespace app\tdadmin\controller;

use app\common\controller\AdminBaseController;
use app\common\model\MemberModel;
use app\common\model\TeacherModel;
use think\Db;
use think\facade\Env;

class IndexController extends AdminBaseController
{
    public function index()
    {

        $requiremntCount = get_option('requirement_count');
        $fruitCount = get_option('fruit_count');
        $teachers = TeacherModel::count();
        $members = MemberModel::count();
        $site = get_option('site_info');
        $start = mktime(0,0,0,date('m'),date('d'),date('Y'));
        $end = mktime(23,59,59,date('m'),date('d'),date('Y'));
        $today_teacher = Db::name('login_log')->where('user_type',0)->where('time' ,'between',date("Y-m-d H:i:s",$start).",".date("Y-m-d H:i:s",$end))->group('teacher_no')->count();
        $today_member = Db::name('login_log')->where('user_type',1)->where('time' ,'between',date("Y-m-d H:i:s",$start).",".date("Y-m-d H:i:s",$end))->group('phone')->count();

        $this->assign([
           'requirement_count'=> $requiremntCount['count'],
           'fruit_count'=> $fruitCount['count'],
           'teacher_count'=> $teachers,
            'member_count' => $members+$teachers,
            'site' => $site,
            'today' => $today_teacher + $today_member
        ]);
    	return $this->fetch('/index');
    }

    public function clear_cache(){
        clear_cache();
    }
}
